import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import top.jfunc.common.http.base.Config;
import top.jfunc.common.http.smart.SmartHttpClient;
import top.jfunc.common.http.smart.SmartHttpClientImpl;

import java.util.Map;

/**
 * @author xiongshiyan at 2019/5/7 , contact me with email yanshixiong@126.com or phone 15208384257
 */
//@EnableSmartHttpClient
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class , scanBasePackages = {"top.jfunc"})
public class TestHttpApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(TestHttpApplication.class, args);
        //Map<String, SmartHttpProperties> beans = applicationContext.getBeansOfType(SmartHttpProperties.class);
        //debug here the smartHttpProperties's properties is not injected correctly

        // If I replace the automatic configuration with the following configuration, an exception occurs.
        // It's like this code doesn't work. @ConditionalOnMissingBean({SmartHttpClient.class}) on SmartHttpAutoConfigure
        ///No qualifying bean of type 'top.jfunc.common.http.smart.SmartHttpClient' available: expected single matching bean but found 2: ApacheSmartHttpClient,smartHttpClient
        Map<String, SmartHttpClient> smartHttpClientMap = applicationContext.getBeansOfType(SmartHttpClient.class);
    }

    @Bean
    public SmartHttpClient smartHttpClient(){
        Config config = Config.defaultConfig().setBaseUrl("http://localhost:9999/http-server-test/");
        SmartHttpClientImpl smartHttpClient = new SmartHttpClientImpl();
        smartHttpClient.setConfig(config);
        return smartHttpClient;
    }
   /* @Bean
    public HttpServiceCreator httpServiceCreator(SmartHttpClient smartHttpClient){
        return new HttpServiceCreator().setSmartHttpClient(smartHttpClient);
    }
    @Bean
    public HttpServiceScanConfigure httpServiceScanConfigure(){
        HttpServiceScanConfigure httpServiceScanConfigure = new HttpServiceScanConfigure(httpServiceCreator(smartHttpClient()));
        httpServiceScanConfigure.setAnnotationClassScan(HttpService.class);
        httpServiceScanConfigure.setScanPackages("top.jfunc.network.controller.client");
        return httpServiceScanConfigure;
    }*/
}
